$(function(){
    window.onload=function () {
        
    var oWrapper = $(".header");
    var nav_item = oWrapper.find('[data-subNav]');
    var sub_nav = $(".sub-nav");
    var sub_nav_c = sub_nav.find('.sub-nav_wrap');
    var item_a = $(".nav-item a")
    // console.log(item_a)
    var timer = null;

    //显示小导航
    nav_item.hover(function(){
        clearTimeout(timer);
        hoverChange();
        var getVal = $(this).attr('data-subNav');
        var subNav_cur = $('.sub-nav_wrap[data-link='+getVal+']');
        var cur_imgs = subNav_cur.find('a');

        goodsShow(subNav_cur);
        showImg(cur_imgs);
    },function(){
        timer = setTimeout(function(){
            outChange();
        },100);
    })

    // 鼠标移入小导航时
    sub_nav.hover(function () {
        clearTimeout(timer);
      }, function () {
        timer = setTimeout(function () {
          outChange();
        }, 100);
      });

    function hoverChange(){
        sub_nav.slideDown(100);
    };

    function outChange(){
        sub_nav.slideUp(100);
    };

    //当前商品容器显示
    function goodsShow(subNav_cur){
        sub_nav_c.hide();

        subNav_cur.show();
    }
  
    // 小列表显示
    function showImg(aImg){

        aImg.css({opacity:0});

        for(var i=0;i<aImg.length;i++){
            aImg.eq(i).stop().animate({opacity:1},500);

            if(i == aImg.length -1){
                clearInterval(timer);
            }
        }

        // 图片移入移出
        aImg.hover(function(){
            $(this).css({opacity:1}).siblings().css({opacity:0.7});
        },function(){
            aImg.css({opacity:.7});
        })
    }
    }
});